<!-- 验证插件 -->
<script src="/static/plugins/jquery-validation/jquery.validate.min.js"></script>
<script src="/static/plugins/jquery-validation/localization/messages_zh.min.js"></script>
<!-- 针对当前主题进行简单封装，精简代码 -->
<script src="/static/sdtheme/scripts/sdvalidate.js"></script>
<!-- CK Editor -->
<script src="https://ckeditor.com/assets/libs/ckeditor4/4.12.1/ckeditor.js"></script>
{{/*<script src="/static/plugins/ckeditor/ckeditor.js"></script>*/}}
<script>
	var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
   $(function () {		
        //验证
        validateInfo();       
    });
    //表单验证及AJAX提交
    function validateInfo() {
        var $thisForm = $('#thisForm');
        $thisForm.sdvalidate({
            rules: {
                Name: {
                    maxlength: 32,
                    required: true
                },
                // Content: {
                //     required: true
                // }
            },
            messages: {},
            submitHandler: function (form) {
				var url ='{{ urlfor "fronted_manage/HistoryController.Edit"}}';
				//var data = $thisForm.serialize();
                var content = CKEDITOR.instances.editor1.getData();
                var name = $("#Name").val();
                var sort = $("#Sort").val();
                var id = $("#Id").val();
                var date = $("#Date").val();
                var data = {Name: name, Sort:sort, Content:content,Id:id,Date:date};
                console.log(data);

                    $.sdpost(url,data,function(re){
					if(re.code === 0){
						parent.layer.msg(re.msg);
						parent.refresh(re.obj);
						parent.layer.close(index);
					}else{
						parent.layer.alert(re.msg,{icon:2,title:'失败'})
					}
				});
               return false;
            }
        });
    }

    function FormSubmit() {
        $("#thisForm").submit();		
    }
    $(function () {
        // Replace the <textarea id="editor1"> with a CKEditor
        // instance, using default configuration.
        CKEDITOR.replace('editor1');
        //bootstrap WYSIHTML5 - text editor
        //$(".textarea").wysihtml5();
    });
</script>